class Solution:
    def numberOfAlternatingGroups(self, colors: list[int], k: int) -> int:
        n = len(colors)
        cnt, leng = 0, 1
        for i in range(-k+2, n, 1):
            if colors[i] != colors[i-1]:
                leng += 1
            else:
                leng = 1
            if leng >= k:
                cnt += 1
        return cnt


if __name__ == '__main__':
    s = Solution()
    print(s.numberOfAlternatingGroups(colors = [1,1,0,1], k = 4))
    print(s.numberOfAlternatingGroups(colors = [0,1,0,1,0], k = 3))
    print(s.numberOfAlternatingGroups(colors = [0,1,0,0,1,0,1], k = 6))
    print(s.numberOfAlternatingGroups(colors = [0,1,0,1,0,1,0,1,0,1,0,1,\
        0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,\
            1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,\
                1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,\
                    0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,\
                        0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,\
                            1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,\
                                1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1], k = 20))
    
    
    